Add config file support (init, validate, runtime loading)#203
Open
rdowavic wants to merge 3 commits intoamitsaha:masterfrom
Open
Add config file support (init, validate, runtime loading)#203rdowavic wants to merge 3 commits intoamitsaha:masterfrom
rdowavic wants to merge 3 commits intoamitsaha:masterfrom
Conversation
Add support for a gitbackup.yml configuration file as an alternative to passing all options as CLI flags. Includes three new capabilities: - gitbackup init: creates a default gitbackup.yml in the current directory - gitbackup validate: validates config file values and required env vars - Runtime loading: when gitbackup.yml exists, it is used as the base config with CLI flags overriding individual values Migration-related flags remain CLI-only. Secrets are always provided via environment variables and are never stored in the config file. Closes amitsaha#166
amitsaha
requested changes
Feb 21, 2026
Owner
amitsaha
left a comment
There was a problem hiding this comment.
Thanks for the PR @rdowavic couple of things i would like us to address:
- Location of the config file - generally, we would follow what other CLI tools do, so, something under the OS specific home/config directory (For e.g. https://github.com/rust-cli/confy/blob/e3e16f7d/README.md#config-file-location). Allow the user to specify a location which then overrides the default location
- To achieve the latter of (1), you will need to update the
switch casefor handlinginitto also look for the the next arguments. I don't like it, but unfortunately, without a overhaul to use a proper subcommand library, we have to manually parse it. - And if we are doing (2), perhaps also add
--helptogitbackup initandgitbackup validate?
If you think we can instead first migrate everything to sub-command driven, we can do that too.
Thoughts?
This is great, and the reason I wanted this support it starts slowly becoming more batch/automated backup process friendly i think.
Address review feedback: - Store config file in OS-specific config directory instead of the current working directory (e.g. ~/.config/gitbackup/gitbackup.yml on Linux, ~/Library/Application Support/gitbackup/gitbackup.yml on macOS) - Add --config flag to gitbackup init, validate, and the main command to allow specifying a custom config file location - Add --help support for init and validate subcommands - Update tests to use explicit config paths instead of os.Chdir - Update README with new config locations and examples
Author
|
okay, thanks for the feedback. I'm now using |
Owner
|
That’s perfect. Thanks will look.
Re sub commands, is cobra still the best option in terms of usability and
simplicity? I haven’t explored the space for sometime now, so keen to hear
your thoughts, perhaps create a separate issue and put your findings in
there?
…On Mon, 23 Feb 2026 at 4:56 pm, Rachel Dowavic ***@***.***> wrote:
*rdowavic* left a comment (amitsaha/gitbackup#203)
<#203 (comment)>
okay, thanks for the feedback. I'm now using os.UserConfigDir() for the
default config location and added in a flag for configuring a custom
location. Also added on --help for the subcommands. I think an overhaul for
the subcommands is a good idea- use cobra? I'd rather do it in a separate
PR once this is merged, does that sound ok?
—
Reply to this email directly, view it on GitHub
<#203 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAD5EVXQEXO5KVRAU6AKX6T4NKI7BAVCNFSM6AAAAACV2PK2RSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTSNBSHAZTMOBRHA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Author
|
Okay I've added a new issue #206 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
gitbackup initsubcommand to create a defaultgitbackup.ymlin the current directorygitbackup validatesubcommand to check config file values and required environment variablesgitbackup.ymlexists, it is automatically loaded at runtime as the base configuration; CLI flags override individual values usingfs.Visit()to detect explicitly set flagsgitbackup.ymlto.gitignoresince it's a user-generated fileMigration-related flags (
-github.createUserMigration, etc.) remain CLI-only. Secrets (tokens, passwords) are never stored in the config file.Closes #166
Test plan
go test ./...passesgitbackup initcreates a validgitbackup.ymlwith correct defaultsgitbackup initerrors if file already existsgitbackup validatecatches invalid service, invalid repo types, and missing env varsgitbackup.ymlexistsgitbackup.ymlwithservice: github+GITHUB_TOKENruns backup successfully